package com.sysssc.pdftest;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

public class SimpleTable {
    public static final String DEST = "./simple_table.pdf";
 
    public static void main(String[] args) throws IOException,
            DocumentException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new SimpleTable().createPdf(DEST);
    }
    public void createPdf(String dest) throws IOException, DocumentException {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(dest));
        document.open();
        PdfPTable table = new PdfPTable(2);
        BaseFont baseFont = BaseFont.createFont("C:/Windows/Fonts/SIMYOU.TTF",BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
        Font FontChinese = new Font(baseFont, 12, Font.NORMAL);
        table.addCell(new Phrase("姓名", FontChinese));
        
        table.addCell(new Phrase("江泽东", FontChinese));
        table.addCell(new Phrase("身份证", FontChinese));
        table.addCell("512921197804280111");
        PdfPCell sumCell = new PdfPCell(new Phrase("合计", FontChinese));
        sumCell.setColspan(2);
        table.addCell(sumCell);
        document.add(table);
        document.close();
    }
 
}